package edu.byui.chat;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

public class GetCommand implements Sub {
	@SuppressWarnings("unchecked")
	public void runSub(ArrayList parameters) {
		String username = (String) ((Command) parameters.get(0)).getUsername();
		// Chat chat = (Chat) parameters.get(1);
		ObjectOutputStream toClient = (ObjectOutputStream) parameters.get(2);
		// ArrayList<Message> messages = chat.getMessagesFor(username);
		GetData getSQL = new GetData();
		ArrayList<Message> messages = getSQL.getMessagesFor(username);
		try {
			toClient.writeObject(messages);
		}
		catch (SecurityException e) {
			System.out.println("A SECURITY ERROR prevented the messages from being delivered!");
			e.printStackTrace();
		}
		catch (IOException e) {
			System.out.println("An IO Exception has prevented the messages from being delivered!");
			e.printStackTrace();
		}
		catch (Exception e) {
			System.out.println("A GENERIC ERROR has prevented the messages from being delivered!");
			e.printStackTrace();
		}
	}
}

//poop